package com.itheima.date;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @Author 王加鑫
 * @Date 2021/5/11 11:25
 * @Version 1.0
 */
public class Demo01 {
    public static void main(String[] args) {
        Date date = new Date();
        long dateTime = date.getTime();
        long oldTime = dateTime - (1000L*3600*24*365*10);
        //时间原点上加上给定的毫秒值
        date.setTime(oldTime);
        // System.out.println(date);

        String time = "1970年10月5日";
        Date birth = getBirth(time);
        long birthTime = birth.getTime();
        //获取系统当前时间
        long currentTimeMillis = System.currentTimeMillis();
        long end = currentTimeMillis - birthTime;
        long day = end / (1000*60*60*24);
        System.out.println(day);
    }

    public static Date getBirth(String time){
        SimpleDateFormat format = new SimpleDateFormat("yyyy年MM月dd日");
        Date date = null;
        try {
             date = format.parse(time);
        } catch (ParseException e) {
            e.printStackTrace();
        }

        return date;

    }
}
